
var couponid=localStorage.getItem('couponid')
console.log(couponid)
var tc=document.querySelector('.tc')
var tcimg=document.querySelector('.tc img')
var xx=document.querySelector('.xx')
var body=document.querySelector('body')
var m=document.querySelector('.ben')

let xhr=new XMLHttpRequest()
xhr.open('get',`http://chst.vip:1234/api/getcouponproduct?couponid=${couponid}`,false)
xhr.onload=function(){
  if(xhr.status===200){
      let res=JSON.parse(xhr.responseText)
//   console.log(res.result)
  var lis=''
  let regExp = /^<[^<]+\s+src="([^''""]*)"/;

  res.result.forEach((ele,ind) => {
  var tu = res.result[ind].couponProductImg.match(regExp)[1];


//   console.log(tu)

      lis+=
      `
         <li class="uli" couponProductid="${ele.couponProductId}">
               <img src="${tu}">
           
              <h5>${ele.couponProductName}</h5>
              <p>${ele.couponProductPrice}</p>
           
              <div>${ele.couponProductTime}</div>
          </li>
      
     `
            })
            
                    m.innerHTML=lis
           
     


            }
            }  
            xhr.send(null)
 

            $(function(){
                $('.uli').click(function(ev){
                 
            
         
                 body.style.background="rgb(17, 16, 16,.9)"
               

            
                    var e=ev||window.event
                    var target=e.target||e.srcElement
                    // if(target.nodeName="LI"){
                    //     tc.style.display="block"
                    //     localStorage.setItem('couponProductid',target.getAttribute('couponProductid'))
                      
                    // }

                    if(target.nodeName==='LI'){
                        tc.style.display="block"
                        localStorage.setItem('couponProductid',target.getAttribute('couponProductid'))
                      
                   }else{
                    tc.style.display="block"

                        localStorage.setItem('couponProductid',target.parentNode.getAttribute('couponProductid'))
     
                   }
                    var pic=$(this).find('img').attr('src')
                    // console.log(pic)

                    $('.tc img').attr('src',pic)
                  
            
                })
            })

                $('.xx').click(function(){
                    tc.style.display="none"
                    body.style.background="rgb(17, 16, 16,.1)"


                })
               
                 $('.tc .icon-xiangyou1').click(function(){
                    var num=+localStorage.getItem('couponProductid')
                    // console.log(num)
                    num++
                    // console.log(num)
                    var pic=$('.uli').eq(num).find('img').attr('src')

                    $('.tc img').attr('src',pic)
                    localStorage.setItem('couponProductid',num)

                  
                  if(num>=56){
                    num=56
                    localStorage.setItem('couponProductid',56)
                  }
                   

                 })
              

                 $('.tc .icon-zuojiantou1').click(function(){
                    var num2=+localStorage.getItem('couponProductid')
                    // console.log(num2)
                    num2--
                    // console.log(num2)
                    var pic=$('.uli').eq(num2).find('img').attr('src')

                    $('.tc img').attr('src',pic).parent()
                    localStorage.setItem('couponProductid',num2)
                  
                   
                    if(num2<1){
                        num2=0
                        localStorage.setItem('couponProductid',num2)
                        var pic=$('.uli').eq(num2).find('img').attr('src')

                        $('.tc img').attr('src',pic)

                    }

                 })
                 $('.box .icon-zuojiantou1').click(function(){

                    location.href="./优惠券页面.html"
                 }
                 )